package com.miage.m1.javabrowser.plugins;

// Pluging texte

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

import javax.swing.JPanel;

import com.miage.m1.javabrowser.interfaces.PlugInterface;


public class TextContent extends JPanel implements PlugInterface {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	String command;
	BufferedReader bis;

	public void initialize(String command) {
		//this.setPreferredSize(new Dimension(800, 3500));
		this.setBackground(Color.white);
		this.setVisible(true);
		System.out.println("Je suis TextContent");
		this.command = command;	
	
		this.repaint();
		this.revalidate();	
	}

	public void paintComponent(Graphics g) {
		String ligne;
		super.paintComponent(g);
		int y = 20;
		try {
			bis = new BufferedReader(new FileReader(command));
			while ((ligne = bis.readLine()) != null) {
				g.drawString(ligne,0, y);
				y+=20;
			}
			this.setPreferredSize(new Dimension(this.getWidth(),y));
			bis.close();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	@Override
	public void objectDisplay(String text) {
		// TODO Auto-generated method stub

	}

}
